#include<string>
#include <iostream>
#include<sstream>

bool prostoe(int n)
{
    for (int i = 2; i < n/2; ++i) { if (n % i == 0) return 0; }
    return 1;
}

int main()
{   
    std::string S;
    std::string num;
    std::string chislo;

    std::getline(std::cin, S); 
  std::stringstream X{S};
    while (std::getline(X, num, ' '))
    {
        if (num == "zero") { chislo += '0'; }
        else if (num == "one") { chislo += '1'; }
        else if (num == "two") { chislo += '2'; }
        else if (num == "three") { chislo += '3'; }
        else if (num == "four") { chislo += '4'; }
        else if (num == "five") { chislo += '5'; }
        else if (num == "six") { chislo += '6'; }
        else if (num == "seven") { chislo += '7'; }
        else if (num == "eight") { chislo += '8'; }
        else if (num == "nine") { chislo += '9'; }
        else 
        { 
            std::cout << "Wrong input"; 
            return 0;
        }
    }

    if (chislo.size () == 3 && chislo[0]!='0') 
    {
        int res = std::stoi (chislo);
        std::cout << res << std::endl;
        int b = res;
        int a = res;
        while(true)
        {
            if (prostoe (a)) 
            {   
                std::cout << a;
                break;
            }
            if(prostoe(b))
            {
                std::cout << b;
                break;
            }
            a++;
            b--;
        }
    }
    else { std::cout << "Wrong input"; }
    return 0;
}